Skip to content

docs(permission): add permission model guide in fumadocs format - #399

Merged
hotlong merged 3 commits into
mainfrom
copilot/document-permission-model
Jan 30, 2026
Merged

hotlong merged 3 commits into
mainfrom
copilot/document-permission-model

Conversation

Copilot AI commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Documents ObjectStack's three-layer access control architecture: RLS (database-level), Permissions (application CRUD), and Sharing (business rules). Clarifies precedence semantics (Final Access = RLS ∩ Permission ∩ Sharing) and evaluation flow.

Location

  • File: content/docs/objectos/permission-model.mdx
  • Section: ObjectOS (System Protocol)
  • Format: Fumadocs MDX with frontmatter and visual components

Content

Core Model (Layers 1-3)

  • RLS: PostgreSQL-inspired row-level security with using/check clauses, role-based policies
  • Object Permissions: CRUD + VAMA (View/Modify All) + lifecycle ops (transfer, restore, purge)
  • Sharing Rules: OWD defaults, criteria-based and owner-based sharing with access levels

Practical Guidance

  • Complete sales org example with RLS tenant isolation, role permissions, and sharing rules
  • Test case matrix showing precedence behavior (e.g., admin in different tenant → RLS blocks)
  • Territory management (parallel to role hierarchy for sales/geo structures)
  • Migration patterns from RBAC and Salesforce

Technical Details

  • Performance optimization (indexing, caching, prefetch strategies)
  • SQL injection prevention in RLS expressions
  • Troubleshooting decision tree for access issues

Schema References

Links to canonical implementations:

  • permission/permission.zod.ts - PermissionSet, ObjectPermission, FieldPermission
  • permission/rls.zod.ts - RowLevelSecurityPolicy with full PostgreSQL semantics
  • permission/sharing.zod.ts - CriteriaSharingRule, OwnerSharingRule, OWD enums
  • permission/territory.zod.ts - Territory model for matrix reporting structures

Example

// Most Restrictive Wins
const access = {
  rls: 'tenant_id = current_user.tenant_id',  // Hard boundary
  permission: { viewAllRecords: true },        // Super-user flag
  sharing: { owd: 'private' }                  // Base restriction
};
// → User sees only their tenant (RLS ∩ Permission ∩ Sharing)
Original prompt

Week 2: Security & Permission Model

Task 2.1: Document Permission Model 📖

文档化权限模型

Files: Create packages/spec/docs/PERMISSION_MODEL.md

Content:

ObjectStack Permission Model

ObjectStack 权限模型

Overview / 概览

ObjectStack 提供三层记录级访问控制:

  1. RLS (Row-Level Security) - 数据库级强制策略
  2. Permission - 应用级 CRUD 权限
  3. Sharing - 业务规则扩展

Precedence Order / 优先级顺序

访问权限计算公式:
Final Access = RLS ∩ Permission ∩ Sharing

Most Restrictive Wins (最严格的规则获胜)

Evaluation Flow / 评估流程

RLS Policies (cannot bypass) ↓ PASS
Object Permissions (CRUD + VAMA) ↓ PASS
Sharing Rules (OWD + Criteria) ↓ PASS
GRANT ACCESS

Layer 1: Row-Level Security (RLS)

Purpose / 用途

PostgreSQL-inspired database-level policies that cannot be bypassed even by admins.

When to Use / 使用场景

  • Multi-tenant data isolation
  • Regulatory compliance (GDPR, HIPAA)
  • Hard security boundaries

Example / 示例

const rlsPolicy: RowLevelSecurityPolicy = {
  name: 'tenant_isolation',
  type: 'restrictive',
  operations: ['select', 'update', 'delete'],
  using: {
    field: 'tenant_id',
    operator: '$eq',
    value: { $context: 'user.tenant_id' }
  }
};
Schema Reference / 架构引用

See permission/rls.zod.ts

Layer 2: Object Permissions

Purpose / 用途

Application-level CRUD permissions with additional modifiers.

Permission Matrix / 权限矩阵

Permission	Abbreviation	Grants
Create	C	Insert new records
Read	R	View records (subject to RLS/Sharing)
Update	U	Edit records (subject to RLS/Sharing)
Delete	D	Delete records (subject to RLS/Sharing)
View All	VA	See all records (bypasses sharing)
Modify All	MA	Edit all records (bypasses sharing)
Lifecycle Permissions / 生命周期权限

Additional permissions for state transitions:

approve - Approve records
publish - Publish records
archive - Archive records
Example / 示例

const permission: ObjectPermission = {
  object: 'sales_order',
  create: true,
  read: true,
  update: true,
  delete: false,
  viewAll: false,
  modifyAll: false,
  rowLevelSecurity: [rlsPolicy] // Links to RLS layer
};
Schema Reference / 架构引用

See permission/permission.zod.ts

Layer 3: Sharing Rules

Purpose / 用途

Salesforce-inspired sharing that extends base permissions.

Organization-Wide Defaults (OWD)

Level	Meaning
Private	Only owner sees record
Public Read Only	Everyone can read
Public Read/Write	Everyone can edit
Sharing Rule Types / 规则类型

Criteria-Based Sharing

{
  type: 'criteria',
  condition: {
    field: 'region',
    operator: '$eq',
    value: 'APAC'
  },
  shareWith: { role: 'regional_manager' },
  accessLevel: 'read'
}
Owner-Based Sharing

{
  type: 'owner',
  ownerField: 'account_owner',
  shareWith: { role: 'sales_team' },
  accessLevel: 'read_write'
}
Schema Reference / 架构引用

See permission/sharing.zod.ts

Composition Rules / 组合规则

Rule 1: RLS is Always Evaluated First

RLS policies filter data at the database level before any application logic.

Example:

User has Permission.viewAll = true
BUT tenant_id RLS policy filters to only their tenant
→ User can ONLY see their tenant's data (RLS wins)
Rule 2: Permission Controls Capabilities

Object permissions define what operations are possible.

Example:

User has Permission.read = false
→ User cannot read ANY records (even if sharing grants access)
Rule 3: Sharing Extends Access

Sharing rules can grant access to records beyond ownership.

Example:

User is NOT owner
BUT sharing rule grants 'read' access to region='APAC' records
→ User can read APAC records (sharing extends)
Complete Example / 完整示例

Scenario / 场景

Sales organization with regional structure.

Configuration / 配置

RLS:

{
  name: 'tenant_isolation',
  type: 'restrictive',
  operations: ['select', 'update', 'delete'],
  using: { field: 'tenant_id', operator: '$eq', value: { $context: 'user.tenant_id' } }
}
Permission:

{
  object: 'opportunity',
  create: true,
  read: true,
  update: true,
  delete: false,
  viewAll: false, // Normal users can't see all
  modifyAll: false
}
Sharing:

{
  owd: 'private', // Default: only owner sees
  rules: [
    {
      type: 'criteria',
      condition: { field: 'stage', operator: '$eq', value: 'closed_won' },
      shareWith: { role: 'sales_manager' },
      accessLevel: 'read'
    }
  ]
}
Test Cases / 测试用例

User	Scenario	Result	Reason
Sales Rep	View own opportunity	✅ PASS	Owner + Permission.read
Sales Rep	View colleague's opp	❌ FAIL	OWD=private, not owner
Sales Manager	View closed_won opp	✅ PASS	Sharing rule grants read
Sales Manager	Edit closed_won opp	❌ FAIL	Sharing only grants 'read'
Admin (different tenant)	View any opp	❌ FAIL	RLS blocks cross-tenant
Implementation Checklist / 实施检查清单

When implementing permission model:

 Define RLS policies for multi-tenant isolation
 Configure object permissions per role
 Set Organization-Wide Defaults
 Create sharing rules for cross-ownership access
 Write integration tests for each layer
 Test composition scenarios
 Document custom permission logic
Best Practices / 最佳实践

Start with RLS - Define hard boundaries first
...

</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

@vercel

vercel Bot commented Jan 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 30, 2026 3:48pm

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Document permission model for ObjectStack docs(permission): add comprehensive permission model guide Jan 30, 2026
Copilot AI requested a review from hotlong January 30, 2026 15:39
@hotlong

hotlong commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

@copilot 文档应该按fumadocs规范,全部英文,放在合适的文件夹位置,需要考虑菜单

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 文档应该按fumadocs规范,全部英文,放在合适的文件夹位置,需要考虑菜单

Updated to follow fumadocs standards:

  • Moved to content/docs/objectos/permission-model.mdx
  • Converted to MDX format with frontmatter
  • Removed all bilingual content (English only)
  • Added to ObjectOS menu in meta.json

Commit: b9bdfd7

Copilot AI changed the title docs(permission): add comprehensive permission model guide docs(permission): add permission model guide in fumadocs format Jan 30, 2026
@hotlong
hotlong marked this pull request as ready for review January 30, 2026 15:53
Copilot AI review requested due to automatic review settings January 30, 2026 15:53
@hotlong
hotlong merged commit 68cce49 into main Jan 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive documentation for ObjectStack's three-layer access control architecture in Fumadocs MDX format. The documentation explains the interaction between RLS (database-level), Permissions (application CRUD), and Sharing (business rules) with the precedence formula Final Access = RLS ∩ Permission ∩ Sharing.

Changes:

  • Documents complete permission model with practical examples from multi-tenant sales organizations
  • Provides test case matrices demonstrating precedence behavior across layers
  • Includes migration guidance from RBAC and Salesforce permission models
  • Adds performance optimization and security best practices sections

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
content/docs/objectos/permission-model.mdx Comprehensive 526-line permission model documentation with examples, test cases, schema references, and implementation guidance following Fumadocs format
content/docs/objectos/meta.json Adds "permission-model" to ObjectOS documentation navigation

This branch was successfully deployed

1 active deployment
Preview — b9bdfd72 Deployed Jan 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants